home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / f2c / may_5_92.lha / f2c.VMay_5_1992 / libF77 / getenv_.c < prev    next >
C/C++ Source or Header  |  1992-05-07  |  879b  |  50 lines

  1. #include "f2c.h"
  2.  
  3. /*
  4.  * getenv - f77 subroutine to return environment variables
  5.  *
  6.  * called by:
  7.  *    call getenv (ENV_NAME, char_var)
  8.  * where:
  9.  *    ENV_NAME is the name of an environment variable
  10.  *    char_var is a character variable which will receive
  11.  *        the current value of ENV_NAME, or all blanks
  12.  *        if ENV_NAME is not defined
  13.  */
  14.  
  15. VOID getenv_(fname, value, flen, vlen)
  16. char *value, *fname;
  17. ftnlen vlen, flen;
  18. {
  19. extern char **environ;
  20. register char *ep, *fp, *flast;
  21. register char **env = environ;
  22.  
  23. flast = fname + flen;
  24. for(fp = fname ; fp < flast ; ++fp)
  25.     if(*fp == ' ')
  26.         {
  27.         flast = fp;
  28.         break;
  29.         }
  30.  
  31. while (ep = *env++)
  32.     {
  33.     for(fp = fname; fp<flast ; )
  34.         if(*fp++ != *ep++)
  35.             goto endloop;
  36.  
  37.     if(*ep++ == '=') {    /* copy right hand side */
  38.         while( *ep && --vlen>=0 )
  39.             *value++ = *ep++;
  40.  
  41.         goto blank;
  42.         }
  43. endloop: ;
  44.     }
  45.  
  46. blank:
  47.     while( --vlen >= 0 )
  48.         *value++ = ' ';
  49. }
  50.